package com.lieve.bpm.entity;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author sunlijiang
 * @date 2020/5/1
 */
@Component
public class UserBean {

    @Resource
    private RepositoryService repositoryService;

    @Resource
    private RuntimeService runtimeService;

    @Resource
    private TaskService taskService;

    @Transactional(rollbackFor = Exception.class)
    public void hello() {
        /*String deploymentId = repositoryService
                .createDeployment()
                .addClasspathResource("processes/hello.bpmn20.xml")
                .deploy()
                .getId();*/
        repositoryService
                .createDeployment()
                .addClasspathResource("processes/applyForLeave.bpmn20.xml")
                .deploy()
                .getId();
        runtimeService.startProcessInstanceByKey("applyForLeave");
    }

    public void complete(String taskId) {
        taskService.complete(taskId);
    }
}
